#include "util.hpp"
#include "data.hpp"
#include "server.hpp"

void FileTest()
{
    aod::FileUtil("./www").CreateDirectory();
    aod::FileUtil("./www/index.html").SetContent("<html></html>");
    std::string body;
    aod::FileUtil("./www/index.html").GetContent(&body);
    std::cout << body << std::endl;
    std::cout << aod::FileUtil("./www/index.html").Size() << std::endl;
}

void JsonTest()
{
    Json::Value val;
    const char* name = "小明";
    int age = 19;
    float score[] = {77.5, 88, 99.5};

    val["姓名"] = name;
    val["年龄"] = age;
    val["成绩"].append(score[0]);
    val["成绩"].append(score[1]);
    val["成绩"].append(score[2]);

    std::string body;
    aod::JsonUtil::Serialize(val, &body);
    std::cout << body << std::endl;

    Json::Value stu;
    aod::JsonUtil::UnSerialize(body, &stu);
    std::cout << val["姓名"].asString() << std::endl;
    std::cout << val["年龄"].asString() << std::endl;
    int sz = val["成绩"].size();
    for (int i = 0; i < sz; i++)
    {
        std::cout << val["成绩"][i] << std::endl;
    }
}

void DataTest()
{
    aod::TableVideo tb_video;
    Json::Value video;
    // video["name"] = "变形金刚";
    // video["info"] = "这是一个会变形机器人的故事，机器人大战，精彩纷呈~";
    // video["video"] = "/video/robot.mp4";
    // video["image"] = "/image/robot.jpg";
    
    // tb_video.Insert(video);
    // tb_video.Update(2, video);

    // tb_video.SelectAll(&video);
    // tb_video.SelectOne(1, &video);
    // tb_video.SelectLike("金刚", &video);
    // std::string body;
    // aod::JsonUtil::Serialize(video, &body);
    // std::cout << body << std::endl;

    tb_video.Delete(1);
}

void ServerTest()
{
    aod::Server server(9090);
    server.RunModule();
}

int main()
{
    // FileTest();
    // JsonTest();
    // DataTest();
    ServerTest();

    return 0;
}